﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Collections.ObjectModel;

namespace UmlDesigner.Model
{
    internal class CodeGenerationSettings
    {
        internal enum GenerationSource
        {
            SelectionOnly,
            CurrentDocument,
            AllDocuments
        }

        internal CodeGenerationSettings(string outDir, string defaultNs, GenerationSource src, bool sln, bool proj, bool dirForProj)
        {
            outputDirectory = outDir;
            defaultNamespace = defaultNs;
            source = src;

            createSln = sln;
            createProj = proj;
            createDirForProj = dirForProj;

            errors = new StringBuilder();
            processedFiles = new Collection<string>();
        }

        private string outputDirectory;
        private string defaultNamespace;
        private GenerationSource source;
        private StringBuilder errors;
        private bool createSln;
        private bool createProj;
        private bool createDirForProj;
        private Collection<string> processedFiles;

        internal Collection<string> ProcessedFiles
        {
            get
            {
                return processedFiles;
            }
        }

        internal StringBuilder Errors
        {
            get
            {
                return errors;
            }
        }
        internal string OutputDirectory
        {
            get
            {
                return outputDirectory;
            }
            set
            {
                outputDirectory = value;
            }
        }
        internal string DefaultNamespace
        {
            get
            {
                return defaultNamespace;
            }
        }
        internal GenerationSource Source
        {
            get
            {
                return source;
            }
        }
        internal bool CreateSolution
        {
            get
            {
                return createSln;
            }
        }
        internal bool CreateProject
        {
            get
            {
                return createProj;
            }
        }
        internal bool CreateDirForProject
        {
            get
            {
                return createDirForProj;
            }
        }

        internal void StartNewItem(TextWriter writer, int indentLevel)
        {
            FinishCurrentItem();

            currentItem = writer;
            currentIndent = indentLevel;
        }

        private TextWriter currentItem;
        private int currentIndent;

        internal TextWriter CurrentItem
        {
            get
            {
                return currentItem;
            }
        }
        internal int CurrentIndent
        {
            get
            {
                return currentIndent;
            }
        }

        internal void IncreaseIndent()
        {
            currentIndent++;
        }

        internal void DecreaseIndent()
        {
            currentIndent--;
        }

        internal void WriteIndentedLine(string s)
        {
            for (int i = 0; i != currentIndent; i++)
            {
                currentItem.Write("    ");
            }
            currentItem.WriteLine(s);
        }


        internal void FinishCurrentItem()
        {
            if (currentItem != null)
            {
                currentItem.Close();
                currentItem = null;
            }
        }
    }
}
